package thread;

import org.apache.commons.lang.StringUtils;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * Created by fanzhenyu02 on 2020/6/23.
 */
public class BillProcessThread extends Thread {
    private String processFileName;

    public String getProcessFileName() {
        return processFileName;
    }

    public void setProcessFileName(String processFileName) {
        this.processFileName = processFileName;
    }


    CountDownLatch countDownLatch = new CountDownLatch(1);

    private void runThread(int splitSize) {
        ExecutorService executorService = Executors.newFixedThreadPool(splitSize);
        for (int i = 0; i < splitSize; i++) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            executorService.submit(new Runnable() {
                @Override
                public void run() {
                    try {
                        countDownLatch.await();
                        System.out.println("Thread:" + Thread.currentThread().getName() + ",time: " + System.currentTimeMillis());
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
        }
        countDownLatch.countDown();
    }

    public static void main(String[] args) throws Exception {
//        BillProcessThread test = new BillProcessThread("prefix", 5);
//        test.runThread();


        File writeFile = new File("/Users/vonmax/Downloads/merge/testFile.txt");
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(writeFile), "UTF-8"));

//        String lineStr;
//        int line = 0;
//        String newLineStr;
//        while ((lineStr = bufferedReader.readLine()) != null) {
//            line++;
//            if (line == 1) {
//                newLineStr = lineStr;
//            } else {
//                //处理每一条流水
//                newLineStr = handleBillLine(lineStr);
//            }
//            if (StringUtils.isBlank(newLineStr)) {
//                logHandler.logErrObj("handle bill line error, error origin line:" + lineStr);
//                return false;
//            } else {
//                bufferedWriter.write(newLineStr);
//            }
//
//        }


        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 1024; j++) {
                bufferedWriter.write(i + 1 + "\n");
            }
        }


        bufferedWriter.flush();
        bufferedWriter.close();


    }


}
